package com;

import java.math.BigDecimal;
import java.math.BigInteger;

public class JInzhi {
    static public void main(String[] argv) {
        //定义一个十进制值
        int valueTen = 15;
        //将其转换为十六进制并输出
        String strHex = Integer.toHexString(valueTen);
        System.out.println(" [十进制]---->[十六进制] " + strHex);

        String result = Integer.toBinaryString(valueTen);
        System.out.println(" [十进制]---->[二进制] " + result);

        String result32 = to32String(BigInteger.valueOf(valueTen));
        System.out.println(" [十进制]---->[三十二进制] " + result32);
    }

    private static String s36bit_const = "0123456789abcdefghjklmnprstvwxyz";

    private static String to32String(BigInteger i) {
        BigDecimal divide = new BigDecimal(32);
        BigDecimal decimal = new BigDecimal(i);
        String res = "";
        while (BigDecimal.ZERO.compareTo(decimal) != 0){
            BigDecimal[] divRes = decimal.divideAndRemainder(divide);
            decimal = divRes[0];
            res =  s36bit_const.charAt(divRes[1].intValue()) + res;
        }
        return res;
    }
}
